package cn.mj.netty.serialize;

import java.util.concurrent.TimeUnit;

import io.netty.channel.ChannelFuture;

public class SendMsg {
	
	/**
	 * 测试 netty的超时重连
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		ChannelFuture channelFuture = ClientUtil.getChannelFuture();
		channelFuture.channel().writeAndFlush(new Request("0", "hello", "0"));
		System.out.println("发送完毕");
//		channelFuture.channel().closeFuture().sync();
		
		//启动一个子线程，测试超时重连
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				ChannelFuture channelFuture = null;
				try {
					TimeUnit.SECONDS.sleep(10);
					channelFuture = ClientUtil.getChannelFuture();
				} catch (Exception e) {
					e.printStackTrace();
				}
				channelFuture.channel().writeAndFlush(new Request("0", "hello，我又来了", "0"));
			}
		}).start();
	}
}
